/*
 * Hibiscus is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 3 of the License,
 * or (at your option) any later version.
 *
 * Hibiscus is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Hibiscus; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 *
 * Copyright (C) 2003 Tetete - http://tetete.hu.
 */
package hu.tetete.hibiscus.propertytree;

import android.app.ListActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

import hu.tetete.hibiscus.dal.PropertyDao;
import hu.tetete.hibiscus.dal.TaxonDatabaseOpenHelper;
import hu.tetete.hibiscus.edittaxon.EditTaxonService;
import hu.tetete.hibiscus.model.Property;

/**
 * TODO javadoc.
 * @deprecated Don't use any more!
 */
@Deprecated
public class PropertyTreeListActivity extends ListActivity {

    private static final String TAG = PropertyTreeListActivity.class.getName();

    private PropertyTreeListAdapter      myAdapter;
    private PropertyDao                  propertyHandler;
    private PropertyTreeService          propertyTreeService;

    /**
     * Intent parameter.
     */
    public enum INTENT_EXTRA {
        /** A property object. */
        PROPERTY,
        /** The values. */
        VALUES
    }

    /**
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.propertyHandler = new PropertyDao(new TaxonDatabaseOpenHelper(this));

        final Intent incomeIntent = getIntent();
        final Property<?> property = (Property<?>)incomeIntent.getExtras().get(INTENT_EXTRA.PROPERTY.name());

        final Intent intent = new Intent(this, EditTaxonService.class);
        bindService(intent, this.mConnection, Context.BIND_AUTO_CREATE);


        this.myAdapter = new PropertyTreeListAdapter(this,
                this.propertyHandler.getPropertyChildrenById(property == null ? null : property.getId()),
                this.propertyTreeService,
                PropertyTreeListActivity.class);
        setListAdapter(this.myAdapter);

//        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.action_bar);

//        final TextView titleView = (TextView)findViewById(R.id.titleText);
//        titleView.setText(property == null ? "Property Tree" : property.getName());

//        final View homeButton = findViewById(R.id.homeButton);
//        homeButton.setOnClickListener(new View.OnClickListener() {
//
//            @Override
//            public void onClick(final View v) {
//                Toast.makeText(PropertyTreeListActivity.this, "Home", Toast.LENGTH_LONG).show();
//            }
//        });
    }

    /**
     * @see android.app.Activity#onStart()
     */
    @Override
    protected void onStart() {
        super.onStart();
    }

    /**
     * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
     */
    @Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.i(TAG, "RequestCode: " + requestCode + " ResultCode: " + resultCode);
    }

    /** Defines callbacks for service binding, passed to bindService(). */
    private final ServiceConnection mConnection = new ServiceConnection() {

        @Override
        public void onServiceConnected(final ComponentName className,
                final IBinder service) {
            // We've bound to LocalService, cast the IBinder and get LocalService instance
//            final NewTaxonServiceBinder binder = (NewTaxonServiceBinder) service;
//            PropertyTreeListActivity.this.propertyTreeService = binder.getService();
//            mBound = true;
        }

        @Override
        public void onServiceDisconnected(final ComponentName arg0) {
//            mBound = false;
        }
    };

}
